Intro
Tags: #◇Computer Science #◇CCDSALG #◇Intro #◇Conceptual #◇M1
◇Overview
An algorithm is any well-defined computational procedure that takes value(s) as input and produces some value(s) as output in a finite amount of time. The main design issues to consider are correctness and efficiency (performance in terms of time and space).
Analyzing an algorithm involves studying its behavior to predict its performance. This includes understanding what happens as the input size gets larger and how much resources (time and memory) are used. The purpose of this analysis is to predict the behavior of algorithms without implementing them, and to compare different algorithms to determine the best one for a given purpose. While exact prediction is not possible due to numerous factors, the analysis provides a useful approximation.
There are two primary methods for analysis:
- A Posteriori Analysis: An empirical analysis where the program is implemented using a programming language, executed on an actual machine, and exact time and space usage are measured.
- A Priori Analysis: A theoretical analysis where the program is analyzed assuming all factors are constant and independent of specific implementation details.
Assumptions for A Priori Analysis (RAM Model)
A Priori Analysis relies on the Random-Access Machine (RAM) model with the following assumptions:
- Algorithms are implemented as computer programs.
- They run on a generic, single-processor, random-access machine model.
- Instructions are executed sequentially, one at a time (no concurrent operations).
- Each instruction or data access takes a constant amount of time.
- The RAM model contains standard instructions commonly found in real computers.
Order of Growth
The rate of growth, or order of growth, of an algorithm is an approximation of the time required by the algorithm as the input size increases.
- Input size usually refers to the number of items in the input.
- Running time is the number of instructions or data accesses executed, independent of a specific computer but within the RAM model framework. The running time for an input size is the sum of the running times of each statement executed.
- It considers only the leading term of the running time polynomial (e.g., in , it focuses on ).
◇Important Formulas
Running time is represented by order of growth classes (Big-O notation). If an algorithm takes time for input size , you can estimate the time for a larger input size using ratios, depending on the complexity class:
- Constant:
- Logarithmic:
- Linear:
- Linearithmic:
- Quadratic:
- Cubic:
- Exponential:
◇Worked Examples
Example 1: Scaling Input Size
If an algorithm takes 1 second to run a problem with an input size of (), what is the approximate time for that algorithm to run a problem with an input size of ()?
- : second
- : seconds
- : seconds
- : seconds
- : seconds
- : seconds
- : seconds
◇References & Navigation
- Related Notes: ◇Introduction to Algorithm Analysis